//
//  TJBaseController.m
//  CrossBorderPayment
//
//  Created by hc-101 on 2020/6/9.
//  Copyright © 2020 xtjun. All rights reserved.
//

#import "TJBaseController.h"


@interface TJBaseController ()

@end

@implementation TJBaseController

- (void)viewDidLoad {
    [super viewDidLoad];
 
 
    self.view.backgroundColor = UIColor.whiteColor;
    if (!self.hiddenNavigationBar)  [self.view addSubview:self.navigationBar];

}

- (void)addBackButton {
    self.navigationBar.leftBarButton = [TJButtonBarButton barButtonBackButtonTarget:self action:@selector(popViewController)];
}

- (void)popViewController {
//    if(self.presentingViewController) {
//        [self dismissViewControllerAnimated:YES completion:nil];
//    } else {
        [self.navigationController popViewControllerAnimated:YES];
//    }
}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    
 
    [self.view bringSubviewToFront:self.navigationBar];
}

- (TJNavigationBar *)navigationBar {
    if (!_navigationBar) {
        _navigationBar = [[TJNavigationBar alloc] init];
        _navigationBar.titleTextColor = [UIColor blackColor];
        _navigationBar.title = self.title;
    }
    return _navigationBar;
}

- (UIActivityIndicatorView *)activityIndicatorView {
    if (!_activityIndicatorView) {
        _activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray size:CGSizeMake(20, 20)];
        [self.view addSubview:_activityIndicatorView];
        _activityIndicatorView.center = self.view.center;
    }
    return _activityIndicatorView;
}


- (void)setHiddenNavigationBar:(BOOL)hiddenNavigationBar {
    _hiddenNavigationBar = hiddenNavigationBar;
    if (hiddenNavigationBar) [_navigationBar removeFromSuperview];
}

- (void)setHiddenBackButton:(BOOL)hiddenBackButton {
    _hiddenBackButton = hiddenBackButton;
    self.navigationBar.hiddenBackButton = hiddenBackButton;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}
 

@end
